package com.bytezero.login_test.network;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * @author Bytezero_zhenglei!
 * @package com.bytezero.login_test.network
 * @fileName
 * @data 2022/1/27 15:59
 * @description
 * @TODO
 * @email 420498246@qq.com
 */
public class RetrofitClient {
    private static volatile RetrofitClient mInstance;
    private static final String BASE_URL = "https://raw.githubusercontent.com/";
    //private static final String BASE_URL = "http://a4z189u.nat.ipyingshe.com/tmall/";
    private Retrofit retrofit;

    private RetrofitClient() {

    }

    public static RetrofitClient getmInstance() {
        if (mInstance == null) {
            synchronized (RetrofitClient.class) {
                if (mInstance == null) {
                    mInstance = new RetrofitClient();
                }
            }
        }
        return mInstance;

    }

    public <T> T getService(Class<T> cls) {
        return getRerotifit().create(cls);
    }

    private synchronized Retrofit getRerotifit() {
        if (retrofit == null) {
            retrofit = new Retrofit
                    .Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
                    .build();

        }
        return retrofit;
    }
}
